---
description: Using Hasura with a DO Postgres database
title: 'Cloud: Using Hasura Cloud with a DigitalOcean Postgres database'
keywords:
  - hasura
  - docs
  - existing database
  - guide
  - digital ocean
  - digitalocean
sidebar_label: DigitalOcean Postgres
sidebar_position: 10
---

import Thumbnail from '@site/src/components/Thumbnail';
import HeadingIcon from '@site/src/components/HeadingIcon';

# Connecting Hasura to a DigitalOcean Postgres Database

## Introduction

This guide explains how to connect a new or existing
[DigitalOcean Postgres](https://www.digitalocean.com/products/managed-databases-postgresql) database to a Hasura
instance, either on [Hasura Cloud](https://cloud.hasura.io?skip_onboarding=true) or via one of our
[self-hosted](/deployment/deployment-guides/index.mdx) solutions. If you're exploring DigitalOcean Postgres and are
interested in migrating an existing Postgres database - such as from Heroku - check out their
[docs](https://docs.digitalocean.com/products/databases/postgresql/how-to/migrate/) before continuing below.

:::info Note

If you plan on using Hasura Cloud, which we recommend, follow steps 1 and 2 below. If you're self-hosting a Hasura
instance and already have a project running, skip to [step 3](#create-pg-db-do).

:::

## Step 1: Sign up or log in to Hasura Cloud

Navigate to [Hasura Cloud](https://cloud.hasura.io/signup/?pg=docs&plcmt=body&cta=navigate-to-hasura-cloud&tech=default)
and sign up or log in.

## Step 2: Create a Hasura Cloud project {#create-hasura-project-do}

On the Hasura Cloud dashboard, create a new project:

<Thumbnail src="/img/cloud-dbs/create-hasura-cloud-project.png" alt="Create Hasura Cloud project" />

After the project is initialized successfully, click on `Launch Console` to open the Hasura Console in your browser.

On the Hasura Console, navigate to the `Data` tab and choose `Connect Existing Database`. Hasura will prompt you for a
Postgres Database URL. We'll create this in the next step and then come back here.

<Thumbnail src="/img/cloud-dbs/existing-db-setup.png" alt="Hasura Cloud database setup" width="700px" />

## Step 3: Create a Postgres DB on DigitalOcean {#create-pg-db-do}

Log into [DigitalOcean](https://cloud.digitalocean.com/).

On the top right, click the `Create` button. Then click on `Databases`:

<Thumbnail src="/img/cloud-dbs/do/create-database.png" alt="Create database on DigitalOcean" />

Scroll down and choose a `Cluster configuration`, as well as a `Datacenter` based on your requirements.

Scroll to the bottom and choose a unique database cluster name. Also, select a project the new database will be
associated with.

<Thumbnail src="/img/cloud-dbs/do/cluster-name.png" alt="Select cluster name for database on DigitalOcean" />

Then click `Create a Database Cluster`.

## Step 4: Allow connections to your DB from Hasura

Navigate to the database cluster's `Overview` page:

<Thumbnail src="/img/cloud-dbs/do/db-settings.png" alt="Navigate to database settings in DigitalOcean" />

Scroll down to `Trusted sources` and click the `Edit` button:

<Thumbnail src="/img/cloud-dbs/do/edit-trusted-sources.png" alt="Edit trusted sources for database in DigitalOcean" />

If you're using Hasura Cloud, you can quickly find your IP address from the `Hasura Cloud IP` field on the project's
details view:

<Thumbnail src="/img/projects/hasura-cloud-ip.png" alt="Hasura Cloud IP field" width="1000px" />

:::info Note

If you're using a self-hosted solution, you'll need to determine the IP address manually depending on your hosting
service.

:::

Enter the Hasura IP address that you copied:

<Thumbnail src="/img/cloud-dbs/do/add-hasura-ip.png" alt="Add Hasura IP to database in DigitalOcean" width="700px" />

Then click `Save`.

:::info Note

If you're using a database user other than the default one, make sure to give it the right
[Postgres permissions](/deployment/postgres-requirements.mdx#managed-pg-permissions).

:::

## Step 5: Get the database connection URL {#get-db-url-do}

The structure of the database connection URL looks as follows:

```bash
postgresql://<user-name>:<password>@<public-ip>:<postgres-port>/<db>?sslmode=require
```

To get it, navigate to the database cluster's `Overview` page:

<Thumbnail src="/img/cloud-dbs/do/db-overview.png" alt="Navigate to database overview in DigitalOcean" />

Scroll down to `Connection details`. Select `Public network` on the left and `Connection string` on the right.

<Thumbnail
  src="/img/cloud-dbs/do/connection-string.png"
  alt="Get the database connection string in DigitalOcean"
  width="600px"
/>

Then click the `Copy` button for the next step.

## Step 6: Finish connecting the database

Back on the Hasura Console, enter the database URL that we retrieved in [step 5](#get-db-url-do):

<Thumbnail src="/img/cloud-dbs/do/DO-complete.png" alt="Database setup" width="600px" />

Then click `Connect Database`.

:::info Note

For security reasons, it is recommended to set database URLs as
[env vars](/hasura-cloud/projects/env-vars.mdx#manage-project-env-vars) and using the env vars to connect to the
databases in place of the raw database URLs.

:::

Voilà. You are ready to start developing.

<Thumbnail src="/img/cloud-dbs/hasura-console.png" alt="Hasura Console" />

## Next steps

- You can check out our [30-Minute Hasura Basics Course](https://hasura.io/learn/graphql/hasura/introduction/) and other
  [GraphQL & Hasura Courses](https://hasura.io/learn/) for a more detailed introduction to Hasura.

- If using Hasura Cloud, you can also click the gear icon to manage your Hasura Cloud project. (e.g. add
  [collaborators](/hasura-cloud/projects/collaborators.mdx#manage-project-collaborators),
  [env vars](/hasura-cloud/projects/env-vars.mdx#manage-project-env-vars) or
  [custom domains](/hasura-cloud/domains.mdx#manage-project-domains)).

<Thumbnail src="/img/getting-started/project-manage.png" alt="Project actions" width="860px" />

:::info Note

For more information on which Postgres features we support, check out [this page](/databases/feature-support.mdx).

:::
